function MyGames(doc, ui)
{
    this.element = doc.createElement("div");
	this.element.className = "mygames-container";
   
    var listelement = doc.createElement("div");
    listelement.innerHTML = "Waiting";
    this.element.appendChild(listelement);

    function makeListElement(player, currentGameId, game)
    {
        var div = doc.createElement("div");
        div.className = "mygame";
        div.setAttribute("currentGame", (game.id == currentGameId) ? "true" : "false");
        div.onclick = function(evt) { ui.changeGame(game.id); }   
        
        var players = doc.createElement("div");
        players.className = "players";
        div.appendChild(players);
        
        var redplayer = doc.createElement("span");
        redplayer.innerText = game.players[0];
        redplayer.setAttribute("currentPlayer", (game.currentSide() == 0) ? "true" : "false");
                
        var versus = doc.createElement("span");
        versus.innerText = "vs.";
        
        var blueplayer = doc.createElement("span");
        blueplayer.innerText = game.players[1];
        blueplayer.setAttribute("currentPlayer", (game.currentSide() == 1) ? "true" : "false");
        
        players.appendChild(redplayer);
        players.appendChild(versus);
        players.appendChild(blueplayer);
        
        var turndiv = doc.createElement("div");
        var turnlab = doc.createElement("span");
        turnlab.className = "label";
        turnlab.innerText = "Turn";
        var turnval = doc.createElement("span");
        turnval.className = "value";
        turnval.innerText = "" + game.currentTurn();
        turndiv.appendChild(turnlab);
        turndiv.appendChild(turnval);
        
        div.appendChild(turndiv);
                                
        return div;
    }

    this.updateCurrentGame = function(player, game, fsm)
    {
    }
    
    this.updateGamesList = function(player, currentGameId, games)
    {
        var newlist = doc.createElement("div");
		newlist.className = "mygames-list"
    
        for(var index in games)
        {
            var game = games[index];
            if(!game.initialized()) continue;
            newlist.appendChild(makeListElement(player, currentGameId, game));
        }
        
        this.element.removeChild(listelement);
        listelement = newlist;
        this.element.appendChild(listelement);
    }
}


